package kr.ac.hanyang.cs.jhpark;

import java.util.ArrayList;

import android.app.Activity;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;


public class NewTask extends ListActivity {


	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	
	    // TODO Auto-generated method stub
        TaskAdapter m_adapter						= new TaskAdapter(this, R.layout.taskrow_newtask, CastSkill.getSkillSet());
        setListAdapter(m_adapter);

	}

 
    private class TaskAdapter extends ArrayAdapter<String[]> {
    	private ArrayList<String[]> items			= null;
    	
    	public TaskAdapter(Context context, int textViewResourceId, ArrayList<String[]> items) {
    		super(context, textViewResourceId, items);
    		this.items								= items;
    	}

    	@Override
    	public View getView(int position, View convertView, ViewGroup parent) {
    		View v									= convertView;

    		if (v == null) {
    			LayoutInflater vi					= (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    			v									= vi.inflate(R.layout.taskrow_newtask, null);
            }


    		String[] taskInfo						= items.get(position);

    		if (taskInfo != null) {
    			TextView tv							= (TextView) v.findViewById(R.id.NewTaskDlg_txtTaskName);
    			ImageView iv						= (ImageView)v.findViewById(R.id.NewTaskDlg_imgAdd);
    			
    			if (tv != null) {
    				tv.setText(taskInfo[0]);
    				tv.setTag(taskInfo[1]);
    				tv.setOnClickListener(btnClickListner);
    			}

    			if (iv != null) {
    				iv.setTag(taskInfo[1]);
    				iv.setOnClickListener(btnClickListner);
    			}
				
            }

            return v;
    	}


    	private Button.OnClickListener btnClickListner = new Button.OnClickListener() {
    		public void onClick(View v) {
    			// tagging되어 있는 값에 따른 task 설정 Activity 실행
    			String newTask						= (String) v.getTag();

    			if (newTask.equals("APP_LAUNCH")) {
            		Intent intent					= new Intent(new Activity(), SelectDialog.class);
            		startActivityForResult(intent, SelectDialog.SELECT_APP);
    			}
    			else if (newTask.equals("CALL_TEL")) {
    				
    			}
    			else if (newTask.equals("WIFI_ON")) {
    				
    			}
    			else if (newTask.equals("WIFI_OFF")) {
    				
    			}
    		}
    		
    	};

    }
    



}
